<?php
include("./Core/Common.php");
$param=base64_decode($_GET['param']);
$arr=explode("\t",authcode($param,'DECODE',$conf['KEY']));
$version=$arr[0];
$url=$arr[1];
$authcode=$arr[2];
if(!$url || !$authcode)exit("<script language='javascript'>alert('参数输入不完整".$param."');history.go(-1);</script>");

if($arr[3]<time())exit("<script language='javascript'>alert('链接已过期，请返回重新下载');history.go(-1);</script>");

if(!checkauth($url,$authcode))exit("<script language='javascript'>alert('授权码异常，暂时不能获取更新，请联系QQ：2109877665');history.go(-1);</script>");

$file_real=substr($authcode,0,16).'.zip';
$file=ROOT.CACHE_DIR."/{$file_real}";

$file_path=ROOT.PACKAGE_DIR.'/update/';
$file_str=file_get_contents(ROOT.PACKAGE_DIR.'/Authcode.php');
$file_str=str_replace('1000000001',$authcode,$file_str);
file_put_contents($file_path."Core/Authcode.php",$file_str);
$file_name='update.zip';

if(file_exists($file))unlink($file);
$zip = new PclZip($file);
$v_list = $zip->create($file_path ,PCLZIP_OPT_REMOVE_PATH,$file_path);

$file_size=filesize("$file");
header("Content-Description: File Transfer");
header("Content-Type:application/force-download");
header("Content-Length: {$file_size}");
header("Content-Disposition:attachment; filename={$file_name}");
readfile("$file");
?>